﻿<script type="text/javascript">

    $.parser.onComplete = function () {
        var d = new Date();
        $("#riqi_pandian_kaishi").datebox('setValue', d.toLocaleDateString());
        $("#riqi_pandian_jieshu").datebox('setValue', d.toLocaleDateString());
        $("#info_pandianriqi_shuiwenliao").datebox('setValue', d.toLocaleDateString());
        $('#zhandian_pandian').combobox({
            url: 'json/zhandian.json',
            method: 'get',
            valueField: 'zhandian',
            textField: 'zhandian',
            panelWidth: 175,
            panelHeight: 'auto',
            editable: false,
            onLoadSuccess: function () {
                $("#pandian_shuiwenliao").datagrid({
                    url: "handler/xinxi_shuiwenliao_pandian.ashx",
                    method: "post",
                    queryParams: {
                        requestType: '1',
                        uid: window.uid,
                        kid: window.kid,
                        pandianriqi_kaishi: $("#riqi_pandian_kaishi").datebox('getValue'),
                        pandianriqi_jieshu: $("#riqi_pandian_jieshu").datebox('getValue'),
                        zhandian: $("#zhandian_pandian").combobox('getText')
                    },
                    height: document.body.scrollHeight - 180,
                    loadFilter: function (data) {
                        for (var i = 0; i < data.length; i++) {
                            if (data[i].jieshuriqi) {
                                data[i].jieshuriqi = data[i].jieshuriqi.substring(0, 10);
                            }
                        }
                        return data;
                    }
                });
            }
        });

        $("#info_pandianzhandian_shuiwenliao").combobox({
            url: 'json/zhandian.json',
            method: 'get',
            valueField: 'zhandian',
            textField: 'zhandian',
            panelWidth: 200,
            panelHeight: 'auto',
            editable: false,
            loadFilter: function (data) {
                var returnData = [];
                for (var i = 0; i < data.length; i++) {
                    if (data[i].zhandian != "—全部—") {
                        returnData.push(data[i]);
                    }
                }
                return returnData;
            }
        });

        $("#info_pandianwuliao_shuiwenliao").combobox({
            url: 'handler/wuliao.ashx',
            method: 'get',
            queryParams: { wuliaoleixing: "入库物料", uid: window.uid, kid: window.kid,noAll:true },
            valueField: 'id',
            textField: 'wuliao',
            panelWidth: 200,
            panelHeight: 200,
            editable: false,
            onSelect: function (record) {
                $("#info_pandianxinghao_shuiwenliao").combobox({
                    url: 'handler/xinghao.ashx',
                    method: 'get',
                    queryParams: { wuliaoid: record.id, uid: window.uid, kid: window.kid,noAll:true },
                    valueField: 'id',
                    textField: 'xinghao',
                    panelWidth: 200,
                    panelHeight: 200,
                    editable: false,
                    onLoadSuccess: function () {
                        $("#info_pandianxinghao_shuiwenliao").combobox('setValue', '—请选择—');
                    }
                });
            }
        });

        $("#info_pandianxinghao_shuiwenliao").combobox({
            data: [{ xinghao: '—请选择—', selected: true }],
            valueField: 'id',
            textField: 'xinghao',
            panelWidth: 200,
            panelHeight: 200,
            editable: false
        });
    }

    var toolbar_shuiwenliao_pandian = [
        {
            text: '盘点',
            iconCls: 'icon-add',
            handler: function () {
                $("#info_pandianwuliao_shuiwenliao").combobox('setValue', '—请选择—');
                $("#info_pandianxinghao_shuiwenliao").combobox('setValue', '—请选择—');
                $("#info_pandianzhongliang_shuiwenliao").textbox('setText', '0');
                $("#shuiwenliaopandianID").val('');
                $("#edit_pandian_shuiwenliao").dialog('open');
            }
        },
    '-',
    {
        text: '修改',
        iconCls: 'icon-edit',
        handler: function () {
            var cur_row = $("#pandian_shuiwenliao").datagrid('getSelected');
            if (cur_row) {
                $("#info_pandianzhandian_shuiwenliao").combobox('setValue', cur_row.zhandian);
                $("#info_pandianriqi_shuiwenliao").datebox('setValue', cur_row.jieshuriqi);
                $("#info_pandianwuliao_shuiwenliao").combobox('setValue', cur_row.wuliao);
                $("#shuiwenliaopandianID").val(cur_row.id);
               
                $("#info_pandianxinghao_shuiwenliao").combobox({
                    url: 'handler/xinghao.ashx',
                    method: 'get',
                    queryParams: { wuliaoid: cur_row.wuliao, uid: window.uid, kid: window.kid, noAll: true },
                    valueField: 'id',
                    textField: 'xinghao',
                    panelWidth: 200,
                    panelHeight: 200,
                    editable: false,
                    onLoadSuccess: function () {
                        $("#info_pandianxinghao_shuiwenliao").combobox('setValue', cur_row.xinghao);
                    }
                });
                $("#info_pandianzhongliang_shuiwenliao").textbox('setValue', cur_row.benqikucun);
                $("#edit_pandian_shuiwenliao").dialog("open");
            }
            else {
                alert("请选择要修改的盘点信息。");
            }
        }
    },
    '-',
    {
        text: '删除',
        iconCls: 'icon-remove',
        handler: function () {
            $("#pandian_shuiwenliao_dlg").dialog('open');
        }
    }
    ];

    function DelShuiWenLiaoPanDian()
    {
        var curr_row = $("#pandian_shuiwenliao").datagrid('getSelected');
        if (curr_row) {
            $.post('handler/xinxi_shuiwenliao_pandian.ashx', { uid: window.uid, kid: window.kid, requestType: '3', pandianID: curr_row.id }, function (data, status) {
                if (data == "OK") {
                    $("#pandian_shuiwenliao").datagrid('load', {
                        requestType: '1',
                        uid: window.uid,
                        kid: window.kid,
                        pandianriqi_kaishi: $("#riqi_pandian_kaishi").datebox('getValue'),
                        pandianriqi_jieshu: $("#riqi_pandian_jieshu").datebox('getValue'),
                        zhandian: $("#zhandian_pandian").combobox('getText')
                    });
                    $("#pandian_shuiwenliao_dlg").dialog('close');
                }
                else {
                    alert(data);
                    $("#pandian_shuiwenliao_dlg").dialog('close');
                }
            });
        }
        else {
            alert("请选择要删除的盘点信息。");
        }
    }

    function submitPanDianShuiWenLiao() {
        var pandianriqi = $('#info_pandianriqi_shuiwenliao').datebox('getValue');
        var wuliao = $("#info_pandianwuliao_shuiwenliao").combobox('getValue');
        var wuliaomingcheng = $("#info_pandianwuliao_shuiwenliao").combobox('getText');
        var xinghao = $("#info_pandianxinghao_shuiwenliao").combobox('getValue');
        var xinghaomingcheng = $("#info_pandianxinghao_shuiwenliao").combobox('getText');
        var benqikucun = $("#info_pandianzhongliang_shuiwenliao").textbox('getText');
        var zhandian = $("#info_pandianzhandian_shuiwenliao").combobox('getText');
        var shuiwenliaopandianID = $("#shuiwenliaopandianID").val();
        if (wuliaomingcheng == "—请选择—" || xinghaomingcheng == "—请选择—")
        {
            alert("信息不完整，请检查重试...");
            return;
        }
        $.post("handler/xinxi_shuiwenliao_pandian.ashx", {
            requestType: '2',
            uid: window.uid,
            kid: window.kid,
            pandianriqi: pandianriqi,
            wuliao: wuliao,
            xinghao: xinghao,
            wuliaomingcheng: wuliaomingcheng,
            xinghaomingcheng: xinghaomingcheng,
            benqikucun: benqikucun,
            zhandian: zhandian,
            shuiwenliaopandianID:shuiwenliaopandianID
        }, function (data, stutas) {
            if (data == "OK") {
                $("#pandian_shuiwenliao").datagrid('load', {
                    requestType: '1',
                    uid: window.uid,
                    kid: window.kid,
                    pandianriqi_kaishi: $("#riqi_pandian_kaishi").datebox('getValue'),
                    pandianriqi_jieshu:$("#riqi_pandian_jieshu").datebox('getValue'),
                    zhandian: $("#zhandian_pandian").combobox('getText')
                }
                );
            }
            else {
                alert(data);
                $("#edit_pandian_shuiwenliao").dialog('close');
            }
        });
    }

    function clearPanDianShuiWenLiao() {
        $("#edit_pandian_shuiwenliao").dialog('close');
    }

    $("#chaxun_pandian").click(function () {
        $("#pandian_shuiwenliao").datagrid('load', {
            requestType: '1',
            uid: window.uid,
            kid: window.kid,
            pandianriqi_kaishi: $("#riqi_pandian_kaishi").datebox('getValue'),
            pandianriqi_jieshu: $("#riqi_pandian_jieshu").datebox('getValue'),
            zhandian: $("#zhandian_pandian").combobox('getText')
        });
    });

    $("#daochu_pandian").click(function () {
        var dateKaiShi = $("#riqi_pandian_kaishi").datetimebox('getValue');
        var dateJieShu = $("#riqi_pandian_jieshu").datetimebox('getValue');
        var zhanDianStr = $("#zhandian_pandian").combobox('getText').replace('#', "_");
        var yongHu = $("#currentUser").text();
        window.open(encodeURI("http://keaomds.com:10001/?uid=" + window.uid + "&kid=" + window.kid + "&requestType=13&keHuBianHao=" + window.kehubianhao + "&zhandian=" + zhanDianStr + "&kaishi=" + dateKaiShi + "&jieshu=" + dateJieShu + "&yonghu=" + yongHu));

    });

</script>

<div class="easyui-panel" data-options="height:90,border:false" title="数据检索" style="border-top-width: 0px;
    border-bottom-width: 1px; padding: 15px; width:100%">
    <table style="font-size: 12px;">
        <tr>
            <td>
                站点：
            </td>
            <td>
                <input class="easyui-combobox" id="zhandian_pandian" style="width: 175px;" />
            </td>
            <td>
                盘点日期：
            </td>
            <td>
                <input id="riqi_pandian_kaishi" type="text" class="easyui-datebox" data-options="required:true"
                       style="width: 120px">
            </td>
            <td>
                至
            </td>
            <td>
                <input id="riqi_pandian_jieshu" type="text" class="easyui-datebox" data-options="required:true"
                       style="width: 120px">
            </td>
            <td>
                <a id="chaxun_pandian" class="easyui-linkbutton" data-options="iconCls:'icon-search'"
                   style="width: 60px; margin-left: 20px;">查询</a>
            </td>
            <td>
                <a id="daochu_pandian" class="easyui-linkbutton" data-options="iconCls:'icon-export-16'"
                   style="width: 60px">导出</a>
            </td>

        </tr>
    </table>
</div>

<table id="pandian_shuiwenliao" class="easyui-datagrid" title="水稳站后场盘点" data-options="border:false,singleSelect:true,collapsible:false,striped:true,fitColumns:true,toolbar:toolbar_shuiwenliao_pandian" style="width:100%">
    <thead>
        <tr>
            <th data-options="field:'jieshuriqi'">
                盘点日期
            </th>
            <th data-options="field:'wuliaomingcheng'">
                物料名称
            </th>
            <th data-options="field:'xinghaomingcheng'">
                型号
            </th>
            <th data-options="field:'shangqikucun'">
                上期库存(t)
            </th>
            <th data-options="field:'benqijinchang'">
                本期进场(t)
            </th>
            <th data-options="field:'benqikucun'">
                本期库存(t)
            </th>
            <th data-options="field:'benqixiaohao'">
                本期消耗(t)
            </th>
            <th data-options="field:'id',hidden:true">
                编号
            </th>
        </tr>
    </thead>
</table>

<div id="edit_pandian_shuiwenliao" class="easyui-dialog" title="盘点" data-options="modal:true,closed:true,iconCls:'icon-edit',draggable:false,collapsible:false,minimizable:false,maximizable:false,resizable:false"
     style="width: 500px; height: 300px; padding: 10px;">
    <div style="width: 350px; margin: 0 auto;">
        <table cellpadding="5" style="font-size: 13px; margin: 0 auto; padding-top: 20px">
            <tr>
                <td>
                    站点：
                </td>
                <td>
                    <input class="easyui-combobox" id="info_pandianzhandian_shuiwenliao" style="width: 200px;" />
                </td>
            </tr>
            <tr>
                <td>
                    盘点日期:
                </td>
                <td>
                    <input class="easyui-datebox" type="text" id="info_pandianriqi_shuiwenliao" name="info_pandianriqi_shuiwenliao"
                           data-options="width:200"></input>
                </td>
            </tr>
            <tr>
                <td>
                    物料:
                </td>
                <td>
                    <input class="easyui-combobox" type="text" id="info_pandianwuliao_shuiwenliao" name="info_pandianwuliao_shuiwenliao"
                           data-options="width:200"></input>
                </td>
            </tr>
            <tr>
                <td>
                    型号:
                </td>
                <td>
                    <input class="easyui-combobox" type="text" id="info_pandianxinghao_shuiwenliao" name="info_pandianxinghao_shuiwenliao"
                           data-options="width:200"></input>
                </td>
            </tr>
            <tr>
                <td>
                    盘点重量:
                </td>
                <td>
                    <input class="easyui-textbox" type="text" id="info_pandianzhongliang_shuiwenliao" name="info_pandianzhongliang_shuiwenliao"
                           data-options="width:200"></input>
                </td>
            </tr>
        </table>
        <input type="hidden"  id="shuiwenliaopandianID" />
        <div style="text-align: center; padding: 5px">
            <a href="javascript:void(0)" class="easyui-linkbutton" style="width: 75px" onclick="submitPanDianShuiWenLiao()" data-options="iconCls:'icon-ok'">保存</a>
            <a href="javascript:void(0)" class="easyui-linkbutton" style="width: 75px" onclick="clearPanDianShuiWenLiao()" data-options="iconCls:'icon-cancel'">关闭</a>
        </div>
    </div>
</div>

<div id="pandian_shuiwenliao_dlg" class="easyui-dialog" title="删除确认" style="width: 300px; height: 150px;
    padding: 10px" data-options="iconCls: 'icon-help',buttons: '#pandian_shuiwenliao_dlg_buttons',modal:true,closed:true">
    确定要删除水稳料盘点信息吗？
</div>
<div id="pandian_shuiwenliao_dlg_buttons">
    <a href="javascript:void(0)" class="easyui-linkbutton" onclick="javascript:DelShuiWenLiaoPanDian();">
        确定
    </a> <a href="javascript:void(0)" class="easyui-linkbutton" onclick="javascript: $('#pandian_shuiwenliao_dlg').dialog('close')">
        取消
    </a>
</div>

